package com.um.jdy.platform.activity.controller;

import com.um.jdy.common.activity.entity.dto.CouponsDTO;
import com.um.jdy.common.activity.entity.po.Coupons;
import com.um.jdy.common.activity.entity.vo.CouponsVO;
import com.um.jdy.common.activity.service.CouponsService;
import com.um.jdy.platform.activity.entity.dto.CouponsListDTO;
import com.um.jdy.platform.activity.entity.dto.CouponsPageDTO;
import com.um.jdy.platform.activity.entity.dto.SaveCouponsDTO;
import com.um.jdy.platform.activity.entity.vo.CouponsItemVO;
import com.um.jdy.platform.activity.manager.CouponsManager;
import com.um.springboot.starter.annotation.ApiPermission;
import com.um.springboot.starter.annotation.TokenRequired;
import com.um.springboot.starter.entity.Page;
import com.um.springboot.starter.orm.controller.BasePlusController;
import com.um.springboot.starter.orm.entity.Response;
import com.um.springboot.starter.orm.params.ListDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import java.util.List;

/**
 * 控制器：优惠券表
 */
@RestController
@RequestMapping("/api/v1/activity/coupons")
@Api(tags = "CouponsController", description = "优惠券表")
@ApiPermission("coupons")
@TokenRequired
public class CouponsController extends BasePlusController<CouponsManager, CouponsService, Coupons, CouponsDTO, CouponsVO, CouponsPageDTO, CouponsListDTO> {

    @ApiPermission("page")
    @ApiOperation("分页查询优惠券")
    @PostMapping("/get_page")
    public Response<Page<CouponsItemVO>> getCouponsPage(@RequestBody CouponsPageDTO params){
        return Response.success(manager.getPage(params.toPageParams()));
    }

    @ApiPermission("add")
    @ApiOperation(value = "新增优惠券")
    @PostMapping("add_coupons")
    public Response addCoupons(@RequestBody SaveCouponsDTO saveCouponsDTO){
        manager.addCoupons(saveCouponsDTO);
        return Response.success();
    }

    @ApiPermission("update")
    @ApiOperation(value = "编辑优惠券")
    @PostMapping("edit_coupons/{id}")
    public Response editCoupons(@ApiParam(value = "优惠券id") @NotEmpty @PathVariable String id, @RequestBody SaveCouponsDTO saveCouponsDTO){
        manager.editCoupons(id, saveCouponsDTO);
        return Response.success();
    }

    @ApiPermission("edit_status")
    @ApiOperation(value = "修改优惠券状态")
    @PutMapping("status/{activity_coupons_id}/{status}")
    public Response<CouponsVO> editStatus(@ApiParam(value = "优惠券id") @NotEmpty @PathVariable String activity_coupons_id,
                                          @ApiParam(value = "状态") @NotEmpty @PathVariable String status){
        return Response.success(manager.editStatus(activity_coupons_id, status));
    }

    @ApiPermission("edit_merge")
    @ApiOperation(value = "修改与活动叠加使用")
    @PutMapping("activity_merge/{activity_coupons_id}/{is_activity_merge}")
    public Response<CouponsVO> editActivityMerge(@ApiParam(value = "优惠券id") @NotEmpty @PathVariable String activity_coupons_id,
                                                 @ApiParam(value = "与活动叠加使用") @NotEmpty @PathVariable String is_activity_merge){
        return Response.success(manager.editActivityMerge(activity_coupons_id, is_activity_merge));
    }

    @ApiPermission("delete")
    @ApiOperation("删除")
    @DeleteMapping({"{id}"})
    public Response<Object> delete(@PathVariable String id) {
        return manager.delete(id);
    }

    @ApiPermission("delete_all")
    @ApiOperation("批量删除")
    @DeleteMapping
    public Response<Object> deleteIds(@ApiParam(value = "删除的id",required = true) @RequestBody List<String> ids) {
        return manager.deleteIds(ids);
    }


    @ApiPermission("list")
    @ApiOperation("查询优惠券列表")
    @GetMapping("list/{scene_type}")
    public Response<List<CouponsVO>> getList(@ApiParam(value = "场景类型：Goods-商品优惠券 Charge-充电优惠券") @NotEmpty @PathVariable String scene_type) {
        return manager.getList(scene_type);
    }

}
